package com.adonis.ejoy.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.adonis.ejoy.Item.PopPic;
import com.adonis.ejoy.Item.PopStar;
import com.adonis.ejoy.Log.Login;
import com.adonis.ejoy.R;
import com.adonis.ejoy.adapter.ImageLoopAdapter;
import com.adonis.ejoy.adapter.PopPicAdapter;
import com.adonis.ejoy.adapter.PopStarAdapter;
import com.jude.rollviewpager.RollPagerView;

import java.sql.BatchUpdateException;
import java.util.ArrayList;
import java.util.List;


public class SearchFragment extends Fragment {

    private View view;
    private List<PopStar> popStarList = new ArrayList<>();
    private RollPagerView mViewPager;
    private List<PopPic> popPicList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_search, container, false);
        initPopStar();
        //    @BindView(R.id.recycler_view) RecyclerView recyclerView;    卧槽（-_-!）BindView不支持在方法里写
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(view.getContext());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        PopStarAdapter adapter1 = new PopStarAdapter(popStarList);
        recyclerView.setAdapter(adapter1);

        mViewPager = (RollPagerView) view.findViewById(R.id.view_pager);     //图片轮播器的初始化
        mViewPager.setAdapter(new ImageLoopAdapter(mViewPager));

        initPopPic();       //以下为瀑布流的实现
        RecyclerView recyclerViewWF = (RecyclerView) view.findViewById(R.id.RV_waterfall);
        StaggeredGridLayoutManager layoutManagerSG = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL){
            @Override
            public boolean canScrollVertically() {
                return false;
            }  //消除互动歧义，可以快速顺畅的滑动
        };
        recyclerViewWF.setLayoutManager(layoutManagerSG);
        PopPicAdapter popPicAdapter = new PopPicAdapter(popPicList);
        recyclerViewWF.setAdapter(popPicAdapter);

       // recyclerViewWF.addOnScrollListener(getOnBottomListener(layoutManagerSG));   滚动预先加载数据
        return view;
    }


    private void initPopStar() {
        //此功能是从数据库拉取最近（1天？）的排行前十的人
        for (int i = 0; i < 3; i++) {
            PopStar baby = new PopStar("baby", R.drawable.baby);
            popStarList.add(baby);
            PopStar huangbo = new PopStar("huangbo", R.drawable.huangbo);
            popStarList.add(huangbo);
            PopStar linxinru = new PopStar("linxinru", R.drawable.linxinru);
            popStarList.add(linxinru);
            PopStar liuyifei = new PopStar("liuyifei", R.drawable.liuyifei);
            popStarList.add(liuyifei);

        }

    }

    private void initPopPic() {
        //此功能获取排名靠前的所有人的照片一张，此处循环3次处理
        for (int i = 0; i < 3; i++) {
            PopPic popPic1 = new PopPic(R.drawable.poppic1);
            popPicList.add(popPic1);
            PopPic popPic2 = new PopPic(R.drawable.poppic2);
            popPicList.add(popPic2);
            PopPic popPic3 = new PopPic(R.drawable.poppic3);
            popPicList.add(popPic3);
            PopPic popPic4 = new PopPic(R.drawable.poppic4);
            popPicList.add(popPic4);
            PopPic popPic5 = new PopPic(R.drawable.poppic5);
            popPicList.add(popPic5);
            PopPic popPic6 = new PopPic(R.drawable.poppic6);
            popPicList.add(popPic6);
            PopPic popPic7 = new PopPic(R.drawable.poppic7);
            popPicList.add(popPic7);
            PopPic popPic8 = new PopPic(R.drawable.poppic8);
            popPicList.add(popPic8);

        }
    }
}